home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume91 / libraris / sregexp9 / part01 / utils / try.c < prev   
C/C++ Source or Header  |  1991-05-18  |  2KB  |  105 lines

  1.  
  2. #include "sregexpbase.h"
  3. #include "sregexp_protos.h"
  4. #include <libraries/dos.h>
  5. #include <clib/exec_protos.h>
  6. #include <clib/dos_protos.h>
  7. #include <string.h>
  8. #include <assert.h>
  9. #include <stdlib.h>
  10.  
  11. struct SregExpBase *SregExpBase;
  12.  
  13. void
  14. puts(c)
  15. char *c;
  16. {
  17. chkabort();
  18.     Write(Output(),c,strlen(c));
  19.     Write(Output(),"\n",1);
  20. }
  21.  
  22. #include <stdarg.h>
  23.  
  24. extern void vsprintf(char *, char *, va_list);
  25.  
  26. void printf(f, ...)
  27. char *f;
  28. {
  29.     char buff[100];
  30.     va_list va;
  31.  
  32. chkabort();
  33.     va_start(va,f);
  34.     vsprintf(buff,f,va);
  35.     va_end(va);
  36.     Write(Output(),buff,strlen(buff));
  37. }
  38.  
  39. int
  40. brk()
  41. {  /* Don't worry about lost memory for now... */
  42.  
  43. Write(Output(),"BREAK\n",6);
  44.     CloseLibrary(SregExpBase);
  45.     return 1;
  46.  
  47. }
  48.  
  49. int
  50. main(ac,av)
  51. int ac;
  52. char *av;
  53. {
  54.     struct SregExp *pat;
  55.     struct SpathInfo *spi;
  56.     char buff[300],fb[110];
  57.     BPTR    lock;
  58.  
  59.     if (!(SregExpBase = OpenLibrary("sregexp.library",0))) {
  60.     puts("Unable to open library.");
  61.     return 5;
  62.     }
  63.     onbreak(brk);
  64. /*
  65.     assert(pat = ParseSregExp("#?dog"));
  66.  
  67.     if (MatchSregExp("hello dog",pat,1))
  68.     puts("right");
  69.     else
  70.     puts("wrong");
  71.  
  72.     if (MatchSregExp("hello Dog",pat,1))
  73.     puts("right");
  74.     else
  75.     puts("wrong");
  76.  
  77.     if (MatchSregExp("hello Dog",pat,0))
  78.     puts("right");
  79.     else
  80.     puts("wrong");
  81.  
  82.     if (MatchSregExp("hello cat",pat,1))
  83.     puts("right");
  84.     else
  85.     puts("wrong");
  86.  
  87.     FreeSregExp(pat);
  88. */
  89.     assert(pat = ParseSregExp("(Programs|Shell)"));
  90.  
  91.     if (!(spi = AnchorPath("","DCC:#?/dme.refs"))) {
  92.     puts("Couldn't start search.");
  93.     CloseLibrary(SregExpBase);
  94.     return 10;
  95.     }
  96. puts("Path anchored");
  97.     while (NextFile(spi,buff,300,0) != SPE_ALL_DONE) {
  98.     printf("----------> %s\n",buff);
  99.     }
  100.  
  101.     FreeSpathInfo(spi);
  102.  
  103.     CloseLibrary(SregExpBase);
  104. }
  105.